import { reqGetAllTopList } from '../../api/allTopList';
import { ALLTOPLIST } from './mutations-type';
const state = {
	allTopList: [],
	listTop: [],
	listFeature: [],
	listOther: []
};

const actions = {
	async getAllTopList({ commit }) {
		// console.log('actions');
		let topList = await reqGetAllTopList();
		/* let listTop = topList.filter((item)=>{
      return item.ToplistType
    }) */
		// console.log('topList', topList);
		// 筛选出对应条件的数组
		let allTopList = topList.list.reduce(
			(p, c) => {
				if (c.ToplistType) {
					c.isCheck = 0
					p[0].push(c);
					return p;
				}
				if (!c.ToplistType && c.name.indexOf('云音乐') >= 0) {
					c.isCheck = 0
					p[1].push(c);
					return p;
				}
				if (!c.ToplistType && c.name.indexOf('云音乐') < 0) {
					c.isCheck = 0
					p[2].push(c);
					return p;
				}
			},
			[ [], [], [] ]
		);
		// console.log('allTopList', allTopList);
		commit(ALLTOPLIST, allTopList);
	}
};

const mutations = {
	[ALLTOPLIST](state, allTopList) {
		// console.log(allTopList);
		(state.listTop = allTopList[0]), (state.listFeature = allTopList[1]), (state.listOther = allTopList[2]);
		// console.log(state.listTop);
	}
};

const getters = {};

export default {
	state,
	actions,
	mutations,
	getters
};
